package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.mapper.StrategyCatalogMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class StrategyCatalogServiceImpl implements IStrategyCatalogService {

    @Autowired
    private StrategyCatalogMapper strategyCatalogMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return strategyCatalogMapper.deleteByPrimaryKey(id);
    }


    @Override
    public StrategyCatalog selectByPrimaryKey(Long id) {
        StrategyCatalog strategyCatalog = strategyCatalogMapper.selectByPrimaryKey(id);
        return strategyCatalog;
    }

    @Override
    public List<StrategyCatalog> selectAll() {
        return strategyCatalogMapper.selectAll();
    }

    @Override
    public void saveOrUpdate(StrategyCatalog strategyCatalog) {
        if (strategyCatalog.getSequence() == null) {
            int max = strategyCatalogMapper.selectMaxSequenceByStrategyId(strategyCatalog.getStrategy().getId());
             strategyCatalog.setSequence(max+1);
        }

        if (strategyCatalog.getId() == null) {
            strategyCatalogMapper.insert(strategyCatalog);
        }else{
            strategyCatalogMapper.updateByPrimaryKey(strategyCatalog);
        }

    }


    @Override
    public PageInfo getList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<StrategyCatalog> list = strategyCatalogMapper.getList(qo);
        return new PageInfo(list);
    }

    @Override
    public  List<StrategyCatalog> getStrategyCatalogByStrategyId(Long strategyId) {
        return   strategyCatalogMapper.getStrategyCatalogByStrategyId(strategyId);
    }

    @Override
    public List<StrategyCatalog> getCatalogsByStrategyId(Long id) {
        return null;
    }


}
